<?php
ob_clean();

//include_once 'init.php';
    //print_r($_SERVER);DIE;
    // ['HTTP_REQUESTED_X_WITH']
        //页数
        $per_page= empty($_GET['page']) ? 10 :$_GET['page'];

        //设置固定5页的页码数
        $page_num=5;
        //获取当前页数
        $cur_page=empty($_GET['p'])?1:$_GET['p'];
        //页码偏移公式（当前页码-1）*总页码
        $offset=($cur_page-1)*$per_page;

        $pages=getpage($link,'news,cate', $per_page,$page_num,$cur_page);

//$sql="select news.*,cate.name from `news`,`cate` where news.cate_id=cate.id order by news.id limit {$offset},{$per_page} ";

$file='news.*,cate.name';
$where='news.cate_id=cate.id';
$order='news.id desc';
$limit="{$offset},{$per_page}";
$tab='news,cate';
$data=getSelect($tab,$file,$where,$order,$limit);

//print_r($_SERVER);die;
 if(!empty($_SERVER['HTTP_X_REQUESTED_WITH'])){
    $json = array();
    $json['data']=$data;
    $json['pages']=$pages;
    echo json_encode($json);die;
    echo $data;die;
 }

include(VIEW_PATH.$admin.'layout.html');

?>
